home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / audacity / plug-ins / clicktrack.ny < prev    next >
Encoding:
Audacity Nyquits plug-in  |  2010-09-21  |  10.0 KB  |  318 lines

  1. ;nyquist plug-in
  2. ;version 3
  3. ;type generate
  4. ;categories "http://lv2plug.in/ns/lv2core#GeneratorPlugin"
  5. ;name "Click Track..."
  6. ;action "Generating Click Track..."
  7. ;info "by Dominic Mazzoni, modified by David R. Sky\nReleased under terms of the GNU General Public License version 2\nFor help, select one of two help screens in 'Action choice' below."
  8.  
  9. ;control action "Action choice" choice "Generate track, help screen 1, help screen 2" 0
  10. ;control tempo "Tempo [beats per minute]" int "30 - 300 beats/minute" 120 30 300
  11. ;control sig "Beats per measure [bar]" int "1 - 20 beats/measure" 4 1 20
  12. ;control measures "Number of measures [bars]" int "1 - 1000 bars" 16 1 1000
  13. ;control click-track-dur "Optional click track duration [minutes seconds]" string "Whole numbers only" ""  
  14. ;control ticklen "Individual click duration [milliseconds]" int "1 - 100 ms" 10 1 100
  15. ;control offset "Start time offset [seconds]" real "0 - 30 seconds" 0 0 30
  16. ;control click-type "Click sound" choice "ping,noise,tick" 0
  17. ;control q "Noise click resonance - discernable pitch [q]" int "1 - 20" 1 1 20
  18. ;control high "MIDI pitch of strong click" int "18 - 116" 92 18 116
  19. ;control low "MIDI pitch of weak click" int "18 - 116" 80 18 116
  20.  
  21. ; original clicktrack.ny by Dominic Mazzoni,
  22. ; modified by David R. Sky: 
  23. ; string input verification added by Steve Daulton, 2009.
  24. ; added click pitch [user request] and sound types fields September 2007
  25. ; added optional total click track duration field [requested by Mike Mullins] 
  26. ; June 2009
  27. ; added individual click duration field [requested by Quinto Milana]
  28. ; June 2009]
  29. ; original code kept 'as is'.
  30. ; now includes:
  31. ; choice between click sounds [ping {sinewave}, noise or tick],
  32. ; user-set MIDI pitch values for strong and weak clicks,
  33. ; resonance of noise clicks 
  34. ; [higher resonance gives them more discernable pitch],
  35. ; time offset for start of click track,
  36. ; and error-checking code to generate error message
  37. ; for such things as negative value inputs
  38. ; Drip sound generator by Paul Beach,
  39. ; used with permission.
  40. ;
  41. ; Thanks very much to Gale Andrews, who gave extensive visual feedback
  42. ; and suggestions!
  43.  
  44.  
  45. ; view 1 of 2 help screens, or generate click track
  46. (cond ; 'master' cond
  47. ((= action 1) ; display help screen 1
  48. (format nil
  49. "Click Track Generator help - screen 1 of 2
  50.  
  51. Generates a click track at the selected tempo, beats per\nmeasure, and either number of measures or track duration,\nusing selected click sound.
  52.  
  53. 'Tempo': number of beats (clicks) per minute.
  54.  
  55. 'Beats per measure (bar)': For example, 3/4 time means one\nstrong click then two others to form one bar, repeated\ndepending on 'number of measures' or 'click track duration'.
  56.  
  57. 'Optional click track duration': If you enter a value into this\nfield, either [minutes seconds] (separated by a space), or\n[seconds], the generated click track will be at or slightly\nlonger than this duration: the end of the track is extended\ninto a whole measure if the entered duration does not\nproduce this. Use whole numbers only.
  58.  
  59. If you enter a value into this field, the 'number of measures'\nvalue will be ignored.
  60.  
  61.       To generate click track or view help screen 2,\n      restart Click Track and select from 'Action choice'.") ; end format
  62. ) ; end display help screen 1
  63.  
  64. ((= action 2) ; display help screen 2
  65. (format nil
  66. "Click Track Generator help - screen 2 of 2
  67.  
  68. 'Individual click duration': the duration of each individual\nclick, minimum of 1 millisecond (ms) to maximum of 100 ms.
  69.  
  70. 'Start time offset': makes the click track start at a later\ntime than the very beginning (zero seconds), maximum\nof 30 seconds.
  71.  
  72. 'Click sound': choose between ping, noise or tick sound\nfor clicks.
  73.  
  74. 'Noise click resonance': the higher this value, the more\nclearly noise clicks have a tone.
  75.  
  76. 'MIDI pitch of strong/weak click': MIDI values indicate\nwhat pitch to use. C-notes are:
  77.  
  78. 24, 36, 48, 60 (middle C), 72, 84, 96, 108.\nC# (C-sharp) above middle C is 61.
  79.  
  80.       To generate click track or view help screen 1,\n      restart Click Track and select from 'Action choice'.") ; end format
  81. ) ; end display help screen 2
  82.  
  83. (t ; perform clicktrack.ny
  84. (setf click-type (+ click-type 1))
  85.  
  86.  
  87. ; check function: returns 1 on error
  88. ; min and max are allowable min and max values for arg
  89. (defun check (arg min max)
  90. (if (and (>= arg min) (<= arg max))
  91. 0 1))
  92.  
  93.  
  94. ; function to convert a string into a list
  95. (defun string-to-list (string)
  96. (read (make-string-input-stream (format nil "(~a)" string))))
  97.  
  98.  
  99. ; convert minutes-seconds string to a list
  100. ; for example, "4 30" becomes (4 30)
  101. (setf m-s (string-to-list click-track-dur)) 
  102.  
  103.  
  104. ; initialize blank error-msg
  105. (setf error-msg "")
  106.  
  107. ; input values error checks
  108.  
  109. ; tempo
  110. (setf error-msg (if 
  111. (= (check tempo 30 300) 0)
  112. error-msg
  113. (strcat error-msg (format nil
  114. "Tempo ~a outside valid range 30 to 300 bpm
  115. " tempo))))
  116. ; beats per measure
  117. (setf error-msg (if
  118. (= (check sig 1 20) 0)
  119. error-msg
  120. (strcat error-msg (format nil
  121. "Beats per measure ~a outside valid range 1 to 20
  122. " sig))))
  123. ; number of measures
  124. (setf error-msg (if
  125. (= (check measures 1 1000) 0)
  126. error-msg
  127. (strcat error-msg (format nil
  128. "Number of measures ~a outside valid range 1 to 1000
  129. " measures))))
  130. ; time start offset
  131. (setf error-msg (if
  132. (= (check offset 0 30) 0)
  133. error-msg
  134. (strcat error-msg (format nil
  135. "Time offset ~a outside valid range 0 to 30 seconds
  136. " offset))))
  137. ; q
  138. (setf error-msg (if
  139. (= (check q 1 20) 0)
  140. error-msg
  141. (strcat error-msg (format nil
  142. "Filter quality q ~a outside valid range 1 to 20
  143. " q))))
  144. ; high MIDI pitch
  145. (setf error-msg (if
  146. (= (check high 18 116) 0)
  147. error-msg
  148. (strcat error-msg (format nil
  149. "High MIDI pitch ~a outside valid range 18 to 116
  150. " high))))
  151. ; low MIDI pitch
  152. (setf error-msg (if
  153. (= (check low 18 116) 0)
  154. error-msg
  155. (strcat error-msg (format nil
  156. "Low MIDI pitch ~a outside valid range 18 to 116
  157. " low))))
  158.  
  159. ; validate string
  160. (if (not (null m-s)) ; don't test if not set
  161.    (if (= (length m-s) 1) ; if there is only one item
  162.       (setf error-msg (if 
  163.       (integerp (first m-s)) ; first is number
  164.    error-msg
  165.    (strcat error-msg (format nil 
  166. "If used, 'Optional click track duration' must be 
  167. entered as either one number [seconds], or two 
  168. numbers [minutes seconds] separated by a space.
  169. Use whole numbers only.
  170. "))))
  171. ; else if there is more than one item
  172.    (setf error-msg (if (and
  173.       (<= (length m-s) 2) ; there are no more than 2 items and
  174.       (integerp (first m-s)) ; first is number
  175.       (integerp (second m-s))) ; second is number
  176.       error-msg
  177.       (strcat error-msg (format nil 
  178. "If used, 'Optional click track duration' must be 
  179. entered as either one number [seconds], or two 
  180. numbers [minutes seconds] separated by a space.
  181. Use whole numbers only.
  182. "))))))
  183.  
  184. ; optional click track length
  185. ; one number entered
  186. (if (and (integerp (first m-s))(= (length m-s) 1))
  187.    (setf error-msg (if 
  188.    (= (check (first m-s) 0 3660) 0)
  189.    error-msg
  190.    (strcat error-msg (format nil 
  191. "~a seconds is outside valid range 0 to 3660"
  192. (first m-s))))))
  193. ; two numbers entered
  194. (if (and 
  195. (integerp (first m-s))
  196. (integerp (second m-s))
  197. (= (length m-s) 2))
  198.    (setf error-msg (if (and
  199.    (= (check (first m-s) 0 60) 0)
  200.    (= (check (second m-s) 0 59) 0))
  201.    error-msg
  202.    (strcat error-msg (format nil 
  203. "~a is outside valid range 0 to [60 59]"
  204. m-s)))))
  205.  
  206.  
  207. (cond
  208. ; if error-msg is not blank, give error msg
  209. ((> (length error-msg) 0)
  210. (setf error-msg (strcat (format nil
  211. "Error - \n\nYou have entered at least one invalid value:\n
  212. ") error-msg))) ; end error msg
  213.  
  214. ; no error so generate click track
  215. (t
  216. ; duration of 1 click, originally statically 0.01 s
  217. (setf ticklen (* (max 1 (min 100 ticklen)) 0.001))
  218. (setf beatlen (/ 60.0 tempo))
  219.  
  220.  
  221. ; function to generate drip sound clicks
  222. ; code by Paul Beach www.proviewlandscape.com/liss/
  223. ; stretch-abs function makes this sound more like 'tick' sounds
  224. (defun drip (p) ; p is pitch in hz
  225. (lp 
  226. (stretch 1
  227. (mult (exp-dec 0 0.015 0.25) 
  228. ( sim
  229. (mult (hzosc (*  2.40483  p))  0.5 )
  230. (mult (hzosc (*  5.52008  p))  0.25 )
  231. (mult (hzosc (* 8.653  p))  0.125 )
  232. (mult (hzosc (* 11.8  p))  0.0625 )
  233. )
  234. )
  235. 440))
  236.  
  237.  
  238. ; function used to normalize noise and tick clicks
  239. ; this function is necessary because filtering 
  240. ; changes amplitude of filtered noise clicks
  241. (defun normalize (sound)
  242. (setf peak-level (peak sound ny:all))
  243. (scale (/ 1.0 peak-level) sound))
  244.  
  245.  
  246. ; make one measure
  247. (setf measure (stretch-abs ticklen (mult 0.75 
  248. ; pwl is used to add fast [5ms] fade-in and fade-out of clicks
  249. (pwl 0 0 0.005 1 0.995 1 1 0 1)
  250. (cond
  251. ((= click-type 1) ; ping accented clicks
  252. (osc high))
  253. ((= click-type 2) ; noise accented clicks
  254. (normalize (lowpass2 (noise 1) (step-to-hz high) q)))
  255. ((= click-type 3) ; tick accented clicks
  256. (normalize (drip (step-to-hz high)))) ))))
  257. (dotimes (x (- sig 1))
  258.   (setf measure (sim measure
  259.                      (at (* beatlen (+ x 1))                 
  260.                          (stretch-abs ticklen (mult 0.5 
  261. ; again, pwl adds 5ms fade-in and fade-out to clicks
  262. (pwl 0 0 0.005 1 0.995 1 1 0 1)
  263. (cond
  264. ((= click-type 1) ;ping tone unaccented clicks
  265. (osc low))
  266. ((= click-type 2) ; noise unaccented clicks
  267. (normalize (lowpass2 (noise 1) (step-to-hz low) q)))
  268. ((= click-type 3) ; tick unaccented clicks
  269. (normalize (drip (step-to-hz low)))) )))))))
  270. ; make the measure exactly the right length
  271. (setf measure (sim measure
  272.                    (stretch-abs (* sig beatlen) (const 0.0))))
  273.  
  274.  
  275. ; convert click-track-dur to number of measures,
  276. ; otherwise use user's measures value 
  277. (setf measures (if (null m-s)
  278. measures
  279. (/
  280. (if ;2
  281. (= (length m-s) 1)
  282. (first m-s) ; just seconds
  283. (+ (* 60 (first m-s)) (second m-s) ; minutes and seconds
  284. ) ; end +
  285. ) ; end if2
  286. (* sig beatlen)) ; end /
  287. ) ; end if
  288. ) ; end setf measures
  289.  
  290.  
  291. ; round up to next whole number of measures only if 
  292. ; measures > (truncate measures)
  293. (setf measures (if 
  294. (> measures (truncate measures))
  295. (truncate (1+ measures))
  296. (truncate measures)
  297. )) ; end if, setf measures
  298.  
  299.  
  300. ; loop measure n [measures-1] times
  301. (setf result measure)
  302. (dotimes (x (- measures 1))
  303.   (setf result (seq result measure)))
  304. ; add time offset to result,
  305. ; if offset > 0 seconds
  306. (setf result (if (= offset 0) result
  307. (sim (s-rest offset) (at-abs offset (cue result)))))
  308.  
  309. ; return [click track] result
  310. result
  311.  
  312. ) ; end t
  313. ) ; end cond
  314.  
  315. ) ; end t perform clicktrack.ny
  316. ) ; end 'master' cond
  317.